<?php
class Admin_ctl extends Ctl{
    function __construct(){
    }
    function main(array $xxfget) {
        $this::sessver();
		$type=!empty($xxfget['type'])?$xxfget['type']:false;
		if(!$type){
		    $filecount=xdb::getInstance()->getvar("select count(1) from filem where ftype like '公开文件'");
			$newsnew=xdb::getInstance()->getvar("select count(1) from news as n LEFT JOIN user_news as un on n.id=un.nid and un.uid=".XXF_UID." where ntype LIKE '普通信息' and (untype is null or untype like '未读' )");
			$newscount=xdb::getInstance()->getvar("select count(1) from news where ntype like '普通信息'");
			$this::show('admin',compact('newsnew','newscount','filecount'));
		}elseif($type=="detail"){
			$news=xdb::getInstance()->getarray("select n.id as nid,n.uid as uid,ntitle,ntype,n.atime,lnum,untype from news as n LEFT JOIN user_news as un on n.id=un.nid and un.uid=".XXF_UID." where ntype LIKE '普通信息'");
			$this::show('news_detail',compact('news'));
		}elseif($type=="content"){
			$nid=$xxfget['nid'];
			$count=xdb::getInstance()->getvar("select count(1) from user_news where nid=".$nid." and uid=".XXF_UID);
			$query="";
			if($count==0){
				$query="insert into user_news(uid,nid,untype)values(".XXF_UID.",".$nid.",'已读')";
				xdb::getInstance()->query($query);
			}
			xdb::getInstance()->query("update news set lnum=lnum+1 where id=".$nid);
			$newsrow=xdb::getInstance()->getrow("select realname,ntitle,ncontent,ntype,atime,n.lnum as lnum from news as n,user as u where n.uid=u.id and n.id=".$nid);
			$this::show('news_content',compact('newsrow'));
		}elseif($type=="file"){
		    $result=xdb::getInstance()->getarray("select * from filem where ftype like '公开文件'");
		    $this->show('filem_file',compact('result'));
		}elseif($type=="subsys"){
		    $result=xdb::getInstance()->getarray("select * from subsys order by btime asc");
		    $this->show('adminsubsys',compact('result'));
		}
    }
}